home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-06 | 5.7 KB | 203 lines | [TEXT/CWIE] |
- // Program Author: Paul Baxter
- // pbaxter@assistivetech.com
- //
- //
- #include <Speech.h>
- #include <Ctype.h>
- #include <DeskBus.h>
- #include <Retrace.h>
-
- #include "aegetdata.h"
- #include "aerecord.h"
- #include "aeutils.h"
- #include "aetoken.h"
- #include "pref.h"
- #include "globals.h"
-
- // * ****************************************************************************** *
- // * DoGetData
- // * Handles the GetData AppleEvent
- // * ****************************************************************************** *
- pascal OSErr DoGetData(const AppleEvent *theAppleEvent,
- AppleEvent *reply,
- long handlerRefCon)
- {
- #pragma unused (handlerRefCon)
-
- AEDesc directObj = {typeNull, NULL},
- result = {typeNull, NULL};
- Size actualSize;
- DescType returnedType;
- DescType reqType;
- OSErr reqTypeErr,
- err;
-
- // extract the direct object, which is the object
- // whose data is to be returned
- err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeWildCard, &directObj);
- if (noErr != err) goto done;
-
- // now the get the type of data wanted - optional
- reqTypeErr = AEGetParamPtr(theAppleEvent, keyAERequestedType, typeType,
- &returnedType, (Ptr)&reqType, sizeof(reqType), &actualSize);
-
- err = GotRequiredParams(theAppleEvent);
- if (noErr != err) goto done;
-
- // get the data
- err = HandleGetData(&directObj, &result);
- if (noErr != err) goto done;
- // add the result
- err = AddResultToReply(&result, reply, err);
-
- done:
- if (directObj.dataHandle)
- AEDisposeDesc(&directObj);
- if (result.dataHandle)
- AEDisposeDesc(&result);
-
- return(err);
- } // DoGetData
-
-
- // * ****************************************************************************** *
- // * HandleGetData
- // * Coerces theObj into a token which we understand and
- // * extracts the data requested in the token and puts it
- // * into dataDesc.
- // * ****************************************************************************** *
- OSErr HandleGetData(AEDesc *theObj, AEDesc *dataDesc)
- {
- AEDesc objTokenDesc = {typeNull, NULL},
- itemDesc = {typeNull, NULL},
- resultDesc = {typeNull, NULL};
- long index;
- DescType returnedType;
- OSErr err;
-
- // Coerce theObj into a token which we can use -
- // this may involve converting a list of tokens to a list of property tokens
- if (typeObjectSpecifier == theObj->descriptorType)
- err = AEResolve(theObj, kAEIDoMinimum, &objTokenDesc);
- else // Otherwise, just copy it
- err = AEDuplicateDesc(theObj, &objTokenDesc);
-
- if (noErr != err) goto done;
-
- switch (objTokenDesc.descriptorType) {
- case typeMyApplProp:
- err = GetApplicationProperty(&objTokenDesc, dataDesc);
- break;
-
- case typeAEList:
- err = AECountItems(&objTokenDesc, &index);
- if (noErr != err) goto done;
-
- for (; index > 0; index--) {
- err = AEGetNthDesc(&objTokenDesc, index, typeWildCard, &returnedType, &itemDesc);
-
- if (noErr == err) // Call this function recursively if necessary
- err = HandleGetData(&itemDesc, &resultDesc);
-
- if (noErr == err) // Overwrite item in list with descriptor item
- err = AEPutDesc(&objTokenDesc, index, &resultDesc);
- // objTokenDesc is just a copy anyway.
- if (itemDesc.dataHandle)
- AEDisposeDesc(&itemDesc);
- if (resultDesc.dataHandle)
- AEDisposeDesc(&resultDesc);
- }
- // Copy list into result
- err = AEDuplicateDesc(&objTokenDesc, dataDesc);
- break;
-
- default:
- err = errAEWrongDataType;
- }
-
- done:
- if (objTokenDesc.dataHandle)
- AEDisposeDesc(&objTokenDesc);
-
- return(err);
- } // HandleGetData
-
-
- // * ****************************************************************************** *
- // * GetApplicationProperty
- // * Fills dataDesc with the requested application property.
- // * ****************************************************************************** *
- OSErr GetApplicationProperty(const AEDesc *theObjToken, AEDesc *result)
- {
- Str255 name;
- ApplPropToken theApplPropToken;
- AEDesc aDesc = {typeNull, NULL},
- nullDesc = {typeNull, NULL};
- Size tokenSize;
- DescType theType;
- ProcessInfoRec processInfo;
- ProcessSerialNumber currentProcess;
- OSErr err;
-
- err = AECoerceDesc(theObjToken, typeMyApplProp, &aDesc);
- if (noErr != err) goto done;
-
- GetRawDataFromDescriptor(&aDesc, (Ptr)&theApplPropToken,
- sizeof(theApplPropToken), &tokenSize);
-
- switch (theApplPropToken.tokenApplProperty) {
-
- case typeVoiceProperty:
- err = PutPStringToDescriptor(result, (**gPrefs).voice);
- break;
-
- case typeSpeakCharProperty:
- err = PutLongIntToDescriptor(result, (**gPrefs).speakChars);
- break;
-
- case typeSpeakWordProperty:
- err = PutLongIntToDescriptor(result, (**gPrefs).speakWords);
- break;
-
- case typeSpeakSentenceProperty:
- err = PutLongIntToDescriptor(result, (**gPrefs).speakSentence);
- break;
-
- case pBestType: // Return the null descriptor representing
- case pDefaultType: // the application.
- err = AEDuplicateDesc(&nullDesc, result);
- break;
-
- case pClass:
- theType = cApplication;
- err = AECreateDesc(typeType, (Ptr)&theType, sizeof(DescType), result);
- break;
-
- case pName:
- // Clear out the name, and then call the process manager to get
- // the string for the name of our application.
- name[0] = 0;
- processInfo.processInfoLength = sizeof(processInfo);
- processInfo.processName = name;
- processInfo.processAppSpec = NULL;
-
- GetCurrentProcess(¤tProcess);
- GetProcessInformation(¤tProcess, &processInfo);
- // Create an AEDesc returning the application name string
- // returned by the process manager.
- PutPStringToDescriptor(result, name);
- break;
-
- default:
- err = errAEEventNotHandled;
- break;
- }
-
-
- done:
- if (aDesc.dataHandle)
- AEDisposeDesc(&aDesc);
-
- return(err);
- } // GetApplicationProperty
-